package bytes;

import java.io.ByteArrayInputStream;

/**
 * @Description
 * @Author zhaobaolin
 * @Date 2018/11/10
 */
public class ByteArrayInputStreamExample {
    public static void main(String[] args) {
        demo();
    }

    private static void create()
    {
        String str = "1234567890";
        byte[] b = str.getBytes();
        ByteArrayInputStream in1 = new ByteArrayInputStream(b);
        ByteArrayInputStream in2 = new ByteArrayInputStream(b,0,3);//从第0个字节开始读 读3个
    }

    private static void demo()
    {
        String str = "1234567890";
        byte[] b = str.getBytes();
        ByteArrayInputStream in1 = new ByteArrayInputStream(b);

        int num = 5;
        for(int i=0;i<5;i++){
            System.out.print((char) in1.read());//输出：12345
            if(i == 2){
                in1.mark(i);
            }
        }
        in1.reset();
        System.out.println();
        for(int i=0;i<5;i++){
            System.out.print((char) in1.read());//输出：45678
        }

    }
}
